package cn.kgm.makeGodV2.ruleEngine;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-24 10:29
 * @Description: cn.kgm.makeGodV2.ruleEngine.RandomTriggerRule
 */
public class RandomTriggerRule implements RuleStrategy<Double> {
    @Override
    public String getRuleType() {
        return "RANDOM_TRIGGER";
    }

    @Override
    public boolean validate(RuleContext context) {
        return context.getParam("triggerRate") != null;
    }

    @Override
    public RuleResult<Double> execute(RuleContext context) {
        double triggerRate = context.getParam("triggerRate", Double.class);
        double randomValue = Math.random();
        boolean triggered = randomValue <= triggerRate;

        String message = triggered ?
                String.format("随机事件触发成功 (%.1f%%几率)", triggerRate * 100) :
                String.format("随机事件未触发 (%.1f%%几率)", triggerRate * 100);

        return RuleResult.success(message, randomValue);
    }
}
